<template>
    <div>
        <div class="box">
            <div class="container">
                <FormItems
                    ref="form"
                    v-model="formData"
                    :form="formList"
                    :state="state"
                    labelWidth="140px"
                >
                </FormItems>
            </div>
        </div>
    </div>
</template>

<script>
import FormItems from "@/views/finance/manage/formItems/index.vue";
import FormItem from "@/views/finance/reimburs/formItem/index.vue";
export default {
    components: { FormItems, FormItem },
    props: {
        value: {
            required: false,
        },
        state: {
            required: false,
        },
        type: {
            type: String,
            required: false,
        },
    },
    dicts: [],
    data() {
        return {};
    },
    inject: ["_planDicts"],
    computed: {
        formData: {
            get() {
                return this.value;
                return this.useVModel.call(this);
            },
            set(val) {
                this.$emit("input", val);
            },
        },
        planList() {
            return this._planDicts?.() ?? [];
        },
        formList() {
            return [
                {
                    label: "本次交强险金额(年)",
                    placeholder: "请输入金额",
                    type: "input_number",
                    prop: "a",
                },
            ];
        },
    },
    created() {},
    mounted() {},
    methods: {
        valid() {
            return new Promise(async (resolve) => {
                let result = true;
                let refs = Object.values(this.$refs);
                for (let index = 0; index < refs?.length; index++) {
                    const ref = refs[index];
                    if (
                        Object.prototype.toString.call(ref) == "[object Array]"
                    ) {
                        for (let i = 0; i < ref.length; i++) {
                            const element = ref[i];
                            if (element?.valid) {
                                let rc = await element?.valid?.();
                                result = result && rc;
                            }
                            if (element?.validate) {
                                let rf = await this._valid(ref);
                                result = result && rf;
                            }
                            if (element?.form_validate) {
                                let rf = await this._valid(
                                    ref,
                                    "form_validate"
                                );
                                result = result && rf;
                            }
                        }
                    } else {
                        if (ref?.valid) {
                            let rc = await ref?.valid?.();
                            result = result && rc;
                        }
                        if (ref?.validate) {
                            let rf = await this._valid(ref);
                            result = result && rf;
                        }
                        if (ref?.form_validate) {
                            let rf = await this._valid(ref, "form_validate");
                            result = result && rf;
                        }
                    }
                }

                resolve(result);
            });
        },
    },
};
</script>

<style lang="scss" scoped>
.box {
    border-radius: 8px;
    background-color: #fff;
    .title {
        font-size: 14px;
        font-family: PingFangSC, PingFang SC;
        font-weight: 500;
        color: #333333;
        line-height: 22px;
        padding: 15px 0;
        // border-bottom: 1px solid #e9e9e9;
        display: flex;
        align-items: center;
        .tag {
            width: 8px;
            height: 8px;
            background-color: #1890ff;
            border-radius: 100%;
            margin-right: 10px;
        }
    }
}
</style>
